package com.first.nell.components.bar

import android.content.Context
import android.os.Build
import android.util.AttributeSet
import android.view.View


class TopStatusBar : View {

    private var mFirstNellStatusFirstNellBarFirstNellHeight: Int = 0

    constructor(context: Context?) : this(context, null)
    constructor(context: Context?, attrs: AttributeSet?) : this(context, attrs, 0)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : this(context,
        attrs,
        defStyleAttr,
        0)

    constructor(
        context: Context?,
        attrs: AttributeSet?,
        defStyleAttr: Int,
        defStyleRes: Int,
    ) : super(
        context,
        attrs,
        defStyleAttr,
        defStyleRes) {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            mFirstNellStatusFirstNellBarFirstNellHeight = getFirstNellStatusFirstNellBarFirstNellHeight(context)
        }
    }

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), mFirstNellStatusFirstNellBarFirstNellHeight)
    }

    private fun getFirstNellStatusFirstNellBarFirstNellHeight(context: Context?): Int {
        if (mFirstNellStatusFirstNellBarFirstNellHeight == 0) {
            context?.let {
                val res = it.resources
                val resourceId = res.getIdentifier("status_bar_height", "dimen", "android")
                if (resourceId > 0) {
                    mFirstNellStatusFirstNellBarFirstNellHeight = res.getDimensionPixelSize(resourceId)
                }
            }
        }
        return mFirstNellStatusFirstNellBarFirstNellHeight
    }
}